package top.hg.tool.modules.car;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import top.hg.tool.common.exception.CarException;
import top.hg.tool.modules.car.constant.RedisKeyConstant;

/**
 * @Author: skh
 * @Date: 2019/7/18 10:32
 * @Description: 公共服务
 */
@Service
@Slf4j
public class CommonService {
    @Autowired
    private StringRedisTemplate redisTemplate;


    //校验token
    public String validToken(String token) {
        String openId = redisTemplate.opsForValue().get(RedisKeyConstant.car_user_token + token);
        if (StrUtil.isBlank(openId)) {
            throw new CarException(401,"token不存在");
        }
        return openId;
    }

}
